package services

import (
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
	"mygo/app/models"
	"mygo/app/tools"
	"strings"
)

// HandleFbc
func HandleFbc(alarmDetail *models.AlarmDetail, region string, db *gorm.DB, c *gin.Context) {
	str := alarmDetail.Data
	//去除字符串中的空格
	str = strings.Replace(str, " ", "", -1)
	//根据换行符分割
	strArr := strings.Split(str, "\n")
	//删除strArr中长度为0的元素
	for i := 0; i < len(strArr); i++ {
		if len(strArr[i]) == 0 {
			strArr = append(strArr[:i], strArr[i+1:]...)
			i--
		}
	}
	var arr []string
	for i := 0; i < len(strArr); i++ {

		if region == "wz" {
			if alarmDetail.PubType == "警报" {
				if strings.Contains(strArr[i], "根据") {
					arr = append(arr, strArr[i])
				}
				if strings.Contains(strArr[i], "未来24小时") {
					arr1 := strings.Split(strArr[i], "，")
					arr = append(arr, arr1[0]+"，"+arr1[1]+"，")
				}
				if strings.Contains(strArr[i], "请") {
					arr = append(arr, strArr[i])
				}
			} else {
				arr = append(arr, strArr[i])
			}
		} else {
			if alarmDetail.PubType == "警报" {
				if strings.Contains(strArr[i], "根据") {
					arr = append(arr, strArr[i])
				}
				if strings.Contains(strArr[i], "请") {
					alarmDetail.Data1 = strArr[i]
				}
			} else {
				arr = append(arr, strArr[i])
			}
		}
	}
	alarmDetail.Data = strings.Join(arr, "\n")
	tools.SuccessResp(c, "获取成功", alarmDetail)
}
